package com.ufo.unzip.dic;

import com.ufo.unzip.utils.ReadFromFile;
import com.ufo.unzip.utils.UnZipUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static com.ufo.unzip.utils.UnZipUtils.getFiles;

/**
 * @Author ufo
 * @Description TODO
 * @Date 2021/1/20 9:51
 * @Version 1.0
 */
public class main2 {
    public static void main(String[] args) {
        //读取18w个单词
        long startTime =  System.currentTimeMillis();
        String fileName = "D:\\workspace\\idea\\javaweb_ssm_test\\unzip\\src\\main\\resources\\1wwords.txt";
        ArrayList<String> strings = ReadFromFile.readFileByLines(fileName);
        ArrayList<String> string_dealed = new ArrayList<>();
        for (String string : strings) {
            String[] s = string.split("=====");
            string_dealed.add(s[1]);
        }
        System.out.println("总数" + strings.size());
        boolean suc;
        UnZipUtils z = new UnZipUtils();
        String path="F:\\新建文件夹";

        ArrayList<String> pas=new ArrayList<>();
        pas.add("st1069");pas.add("10691069");pas.add("1234");
        pas.addAll(string_dealed);
        System.out.println("总总数："+pas.size());
        List<String> files = getFiles(path);
        int flag=0;
        List<String> sources = files.stream().filter(item -> item.endsWith(".zip") || item.endsWith(".rar")).collect(Collectors.toList());
        for (String source : sources) {
            String dest = source.replace(".zip","").replace(".rar","");
            for (String pa : pas) {
                try {
                    z.unZip(source,dest,pa);
                    suc=true;
                    break;
                } catch (Exception e) {
//                    System.out.println(e);
                    System.out.println(flag++ + pa);
                    continue;
                }
            }
        }
        long endtime =  System.currentTimeMillis();
        long usedTime = (endtime-startTime)/1000;
        System.out.println(usedTime);







    }
}
